package com.company.jrlz.service;

import com.company.jrlz.service.opcua.config.OpcUaClientTemplate;
import com.haulmont.cuba.core.Persistence;
import com.haulmont.cuba.core.sys.AppContext;
import org.springframework.stereotype.Service;
import com.company.jrlz.service.opcua.OpcuaService;

import javax.inject.Inject;

@Service(OpcuaService.NAME)
public class OpcuaServiceBean implements OpcuaService {

    @Inject
    private OpcUaClientTemplate opcUaClientTemplate;

    @Inject
    private Persistence persistence;

    @Inject
    public OpcuaServiceBean(Persistence persistence) {
        this.persistence = persistence;
        AppContext.addListener(new AppContext.Listener() {
            @Override
            public void applicationStarted() {
                doAfterStartup();
            }

            @Override
            public void applicationStopped() {
//            doAfterStopped();
            }
        });
    }

    private void doAfterStartup() {
//        opcUaClientTemplate.addConnectionListener(uaConnectionListener);
        opcUaClientTemplate.connectAlwaysInBackend();

    }

}